home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 3 #12 / IMG 33 Dec 1995.iso / Important Files / MGW1Codeƒ / MGWGraphicsBWLite.c < prev    next >
Text File  |  1995-06-25  |  5KB  |  128 lines

  1. //==============================================================================================\\
  2. //        -------------------------------------------------------------------------------            \\
  3. //    MGWGraphicsBWLite1.h version 1.0.0    copyright © 1993…1995 Jamie McCornack, john calhoun            \\
  4. //        -------------------------------------------------------------------------------            \\
  5. //         Constants and prototypes for Macintosh GameWriter 1.0.0, a training program…            \\
  6. //        …for beginning Mac game programmers. MGW1 includes MGWUtilities1.c, MGWSound1.c,…        \\
  7. //        …MGWGraphics1.c, MGWGraphicsBWLite1.c, HelloWorld.rsrc and an assortment of demo…        \\
  8. //         programs; projects HelloWorld1.π etc. and source code files HelloWorld1.c etc.            \\
  9. //         A tutorial is available in Tricks of the Mac Game Programming Gurus, published…        \\
  10. //        …by Hayden Books                                                                        \\
  11. //                                                                                                \\
  12. //        This code is offered by the copyright holders for no fee and for whatever use…            \\
  13. //        …you care to make of it, but we do hope you remember where it came from.                \\
  14. //                                                                                                \\
  15. //        Please send bug reports to MacGameDev at America OnLine.    macgamedev@aol.com            \\
  16. //        Suggestions and observations are also appreciated.                                        \\
  17. //        Updates and upgrades will be available now and then from the above e-mail address.        \\
  18. //==============================================================================================\\
  19.  
  20. // These functions have no error checking and are dangerous. For instruction only.
  21. // DON'T USE THIS FOR REAL PROGRAMS! Use MGWGraphics1.c instead,…
  22. // …which will require MGWUtilities.c in the program.
  23.  
  24. #include "MGWExterns1.h"
  25. //==============================================================  Functions
  26.  
  27. //--------------------------------------------------------------  CreateOffScreenBitMapLite
  28.  
  29. // Creates an offscreen bitmap, without any error checking.
  30. // If this function fails to create the bitmap, the program crashes.
  31. // DO NOT USE THIS FUNCTION in any real program.
  32.  
  33. void CreateOffScreenBitMapLite (Rect *theRect, GrafPtr *offScreen)
  34. {
  35.     GrafPtr        theBWPort;
  36.     BitMap        theBitMap;    
  37.     long        theRowBytes;
  38.     
  39.     theBWPort = (GrafPtr)(NewPtr(sizeof(GrafPort)));
  40.     OpenPort(theBWPort);
  41.     theRowBytes = (long)((theRect->right - theRect->left + 15L) / 16L) * 2L;
  42.     theBitMap.rowBytes = (short)theRowBytes;
  43.     theBitMap.baseAddr = NewPtr((long)theBitMap.rowBytes * 
  44.         (theRect->bottom - theRect->top));    
  45. //    ERROR CHECKING GOES HERE IN CreateOffScreenBitMap()--see MGWGraphics1.c
  46.     theBitMap.bounds = *theRect;
  47. //    ERROR CHECKING GOES HERE IN CreateOffScreenBitMap()--see MGWGraphics1.c
  48.     SetPortBits(&theBitMap);
  49.     ClipRect(theRect);
  50.     RectRgn(theBWPort->visRgn, theRect);
  51.     EraseRect(theRect);
  52.     *offScreen = theBWPort;
  53. }
  54.  
  55. //--------------------------------------------------------------  KillOffScreenBitMap
  56.  
  57. // Disposes of an offscreen bitmap, and frees the memory for other purposes.
  58.  
  59.  
  60.     void KillOffscreenBitMap (GrafPtr *wasPort)
  61.  
  62.     {
  63.         if (wasPort != nil)
  64.             {
  65.                 ClosePort(*wasPort);
  66.                 *wasPort = nil;
  67.             }
  68.     }
  69.  
  70.  
  71. //--------------------------------------------------------------  LoadGraphicLite
  72.  
  73. // Handy function that loads a PICT graphic, get's its bounds and draws it.
  74. // The port drawn to is assumed the current port.  No scaling is done.
  75.  
  76. void LoadGraphicLite (short thePictID)
  77. {
  78.     Rect        bounds;
  79.     PicHandle    thePicture;
  80.     
  81.     thePicture = GetPicture(thePictID);            // Load graphic from resource fork.
  82.                                                 
  83. //    ERROR CHECKING GOES HERE IN LoadGraphic()--see MGWGraphics1.c
  84.     
  85.     HLock((Handle)thePicture);                    // If we made it this far, lock handle.
  86.     bounds = (*thePicture)->picFrame;            // Get a copy of the picture's bounds.
  87.     HUnlock((Handle)thePicture);                // We can unlock the picture now.
  88.     OffsetRect(&bounds, -bounds.left, -bounds.top);    // Offset bounds rect to (0, 0).
  89.     DrawPicture(thePicture, &bounds);            // Draw picture to current port.
  90.     ReleaseResource((Handle)thePicture);        // Dispose of picture from heap.
  91. }
  92.  
  93. //--------------------------------------------------------------  InitToolbox
  94.  
  95. // This routine doesn't belong in a Graphics file.
  96. // It is here in MGWGraphicsBWLitebecause it needs…
  97. // to go somewhere, and I'm trying to keep HelloWorld1.π short and sweet.
  98. // For the rest of the HelloWorld projects, you'll find this routine in MGWUtilities.c.
  99. //    void InitToolbox (void);
  100.  
  101. //
  102. //        The calls herein MUST be called before you do anything else.
  103. //        Otherwise, you'll get all sorts of System Errors.
  104.  
  105. void InitToolbox (void)
  106. {
  107.     InitGraf(&qd.thePort);        // Initialize QuickDraw variables for our program.
  108.     InitFonts();                // Initialize fonts.
  109.     FlushEvents(everyEvent, 0);    // Clear event queue of any pending events.
  110.     InitWindows();                // Initialize the Window Manager.
  111.     InitMenus();                // Ditto for the Menu Manager.
  112.     TEInit();                    // blah, blah Text Edit.
  113.     InitDialogs(0L);            // blah, blah Dialog Manager.
  114.     InitCursor();                // Set the cursor to the arrow cursor and init.
  115.     
  116.     MaxApplZone();                // Grab application memory.
  117.     
  118.     MoreMasters();                // Allocate a block of master pointers.
  119.     MoreMasters();                // And allocate more.
  120.     MoreMasters();                // And more.
  121.     MoreMasters();                // Hey, lets do it again too.
  122.     
  123.     GetDateTime((unsigned long *)&qd.randSeed);        // Randomize random seed.
  124. }
  125.  
  126. //------------------------------------------------------------------------------------------\\
  127. //                                End MGWGraphicsBWLite.c                                        \\
  128. //------------------------------------------------------------------------------------------\\